use serde::Serialize;

#[derive(Debug, Clone, Serialize)]
pub struct ApiResult<T> {
    pub code: i32,
    pub message: String,
    pub data: Option<T>,
}

impl<T> ApiResult<T> {
    pub fn ok(dt: T) -> Self {
        ApiResult {
            code: 200_00_000,
            message: "OK".to_string(),
            data: Option::Some(dt),
        }
    }

    pub fn error(code: i32, msg: String) -> Self {
        ApiResult {
            code,
            message: msg,
            data: None,
        }
    }

    pub fn new(code: i32, msg: String, data: T) -> Self {
        ApiResult {
            code,
            message: msg,
            data: Some(data),
        }
    }
}
